﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuanLyNhaSach
{
    enum SEARCH_STATE
    {
        NAME, AUTHOR, TYPE, ID
    }
    public partial class TraCuu : Form
    {
        SEARCH_STATE search_state;
        public TraCuu()
        {
            InitializeComponent();
        }

        private void TraCuu_Load(object sender, EventArgs e)
        {
            BusinessLogicLayer.QuanLySachBLL qls = new BusinessLogicLayer.QuanLySachBLL();

            search_state = SEARCH_STATE.NAME;

            this.danh_sach_sach.DataSource = qls.LayDanhSach();
         //   danh_sach_sach.Rows.Add()
        }

        private void txt_tim_kiem_Click(object sender, EventArgs e)
        {
            this.txt_tim_kiem.Text = "";
        }

        private void txt_tim_kiem_TextChanged(object sender, EventArgs e)
        {
            BusinessLogicLayer.QuanLySachBLL qls = new BusinessLogicLayer.QuanLySachBLL();
            switch (search_state)
            {
                case SEARCH_STATE.AUTHOR:
                    list_ten_sach.DataSource = qls.TimKiemTheoTacGia(txt_tim_kiem.Text);
                    list_ten_sach.DisplayMember = "TenSach";
                    break;
                case SEARCH_STATE.ID:
                    list_ten_sach.DataSource = qls.TimKiemTheoMa(txt_tim_kiem.Text);
                    list_ten_sach.DisplayMember = "TenSach";
                    break;
                case SEARCH_STATE.TYPE:
                    list_ten_sach.DataSource = qls.TimKiemTheLoai(txt_tim_kiem.Text);
                    list_ten_sach.DisplayMember = "TenSach";
                    break;
                case SEARCH_STATE.NAME:
                    list_ten_sach.DataSource = qls.TimKiemTheoTen(txt_tim_kiem.Text);
                    list_ten_sach.DisplayMember = "TenSach";
                    break;                    
            }
        }

        private void ra_ma_CheckedChanged(object sender, EventArgs e)
        {

            search_state = SEARCH_STATE.ID;
        }

        private void ra_ten_CheckedChanged(object sender, EventArgs e)
        {

            search_state = SEARCH_STATE.NAME;
        }

        private void ra_theloai_CheckedChanged(object sender, EventArgs e)
        {

            search_state = SEARCH_STATE.TYPE;
        }

        private void ra_tacgia_CheckedChanged(object sender, EventArgs e)
        {

            search_state = SEARCH_STATE.AUTHOR;
        }


    }
}
